//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import store from "@/store/index";
let extension = {
  components: {
    //动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: "", //{ template: "<div>扩展组xx件</div>" },
    gridBody: "",
    gridFooter: "",
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: "",
    modelBody: "",
    modelFooter: ""
  },
  buttons: { view: [], box: [], detail: [] }, //扩展的按钮
  methods: {
    //事件扩展
    getOption(field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        });
      });
      return option;
    },
    onInit() {
      this.single = true;
      this.textInline = true;
      this.ck = false;
      //;
      let _userInfo = store.getters.getUserInfo();
      let parentIDoption = this.getOption("parentID");
      let attributesoption = this.getOption("attributes");
      // let typeNameoption = this.getOption("typeName");
      // let typeCodeoption = this.getOption("typeCode");
      let merchantCodeoption = this.getOption("roleId");
      // typeNameoption.onInput = (val) => {
      //   this.editFormFields[typeCodeoption.field] = this.base.chineseToPinYin(val)
      // }
      if (_userInfo.roleID == 1) {
        parentIDoption.required = false;
        attributesoption.required = false;
        merchantCodeoption.hidden = false;
      } else {
        parentIDoption.required = true;
        attributesoption.required = true;
        merchantCodeoption.hidden = true;
      }
      this.columns.push({
        title: "操作",
        fixed: "right",
        width: 140,
        render: (h, { row, column, index }) => {
          return h("div", { style: {} }, [
            h(
              "a",
              {
                props: {},
                style: {},
                on: {
                  click: e => {
                    this.linkData(row);
                  }
                }
              },
              "编辑"
            )
          ]);
        }
      });
    },
    rowClick({ row, column, event }) {
      //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    modelOpenAfter(row) {
      let isEDIT = this.currentAction == this.const.EDIT;
      if (!isEDIT) {
        let typeNameoption = this.getOption("typeName");
        let typeCodeoption = this.getOption("typeCode");
        typeNameoption.onInput = val => {
          this.editFormFields[typeCodeoption.field] = this.base.chineseToPinYin(
            val
          );
        };
      }
    }
  }
};
export default extension;
